<template>
  <div class="login-container">
    <!-- 登陆页面的返回小箭头部分-->
    <login-back-btn></login-back-btn>

    <!-- 登陆页面的logo图部分-->
    <login-logo></login-logo>

    <!-- 登陆页面中点击登陆或是注册部分的组件 -->
    <login-tab-control @isLogin="isLogin"> </login-tab-control>

    <!-- 登陆页面中输入的部分 -->
    <div class="login-input">
      <el-form ref="loginFormRef" :model="loginForm" :rules="loginFormRules">
        <el-form-item class="login-input-phone border-bottom" prop="phone">
          <el-input
            v-model="loginForm.phone"
            prefix-icon="iconfont iconshouji "
          ></el-input>
        </el-form-item>
        <el-form-item
          class="login-input-password border-bottom"
          prop="password"
        >
          <el-input
            type="password"
            v-model="loginForm.password"
            prefix-icon="iconfont  iconiconset0114"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="danger" class="btn">注册</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import LoginBackBtn from "./components/backButton";
import LoginTabControl from "./components/tabControl";
import LoginLogo from "./components/logo";

export default {
  name: "Login",
  components: {
    LoginBackBtn,
    LoginTabControl,
    LoginLogo,
  },
  methods: {
    isLogin (index) {
      if (index == 0) {
        this.$router.push("/login");
      } else if (index == 1) {
        this.$router.push("/landed");
      }
    },
  },
  data () {
    var checkPhone = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("手机号不能为空"));
      } else {
        const reg = /^1[3|4|5|7|8][0-9]\d{8}$/;
        console.log(reg.test(value));
        if (reg.test(value)) {
          callback();
        } else {
          return callback(new Error("请输入正确的手机号"));
        }
      }
    };
    return {
      //状态码
      code: "",
      //获取的接口数据
      res: {},
      //这里是登陆表单的数据绑定对象
      loginForm: {
        // phone: "15254030529aa",
        // password: "666666",
        phone: "",
        password: "",
      },

      //这是表单规则验证对象
      loginFormRules: {
        phone: [{ validator: checkPhone, trigger: "blur" }],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 3,
            max: 15,
            message: "长度在 3 到 15 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
};
</script>

<style lang="less" scoped>
.login-input/deep/.el-input__inner {
  border: 0;
}
.login-input {
  margin-top: 0.47rem;
  .login-input-phone {
    margin: 0.4rem 0.255rem 0 0.255rem;
    padding-bottom: 0.075rem;
  }
  .login-input-password {
    margin: 0.465rem 0.255rem 0 0.255rem;
    padding-bottom: 0.075rem;
    font-size: 0.14rem;
  }
  .btn {
    width: 1.97rem;
    height: 0.525rem;
    font-size: 0.15rem;
    color: #ffffff;
    text-align: center;
    margin-top: 0.31rem;
    margin-left: 0.89rem;
    background: #d20a0a;
  }
}
</style>
